import OriginJsonp from 'jsonp'
const parseParams = (params) => { // 处理params
  let arr = []
  for (let key in params) {
    arr.push([key, params[key]])
  }
  arr = arr.map(element => element.join('=')).join('&')
  return arr
}
export const jsonp = (url, options, params) => {
  const parsedParams = parseParams(params)
  url = url.indexOf('?') === -1 ? url + '?' + parsedParams : url + '&' + parsedParams
  return new Promise((resolve, reject) => {
    OriginJsonp(url, options, (err, data) => {
      if (err) {
        reject(err)
      } else {
        resolve(data)
      }
    })
  })
}
